package com.zhl.study.exception;

import com.zhl.study.base.BaseException;
import com.zhl.study.enums.IEnum;
import lombok.Data;

import java.io.Serializable;

/**
 * @description 业务异常
 * @Author: z156940l@outlook.com
 * @className BizException
 * @Date: 2023/4/28 10:16
 */
@Data
public class BizException extends BaseException implements Serializable {
    private static final long serialVersionUID = -626237002633226176L;

    public BizException() {
        super();
    }

    public BizException(String message) {
        super(message);
    }

    public BizException(IEnum error, Object data) {
        super(error, data);
    }

    public BizException(IEnum error) {
        super(error, null);
    }

    public BizException(IEnum error, String msg, Object data) {
        super(error, msg, data);
    }

    public static BizException pinlanException(IEnum iEnum) {
        return new BizException(iEnum);
    }

    public static BizException pinlanException(IEnum iEnum, String... msg) {
        if (String.valueOf(iEnum.getMsg()).contains("%s")) {
            iEnum.setMsg(String.format(String.valueOf(iEnum.getMsg()), msg));
        }
        return new BizException(iEnum);
    }
}
